//
//  MemoryInfo.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/3/12.
//  
  

#import "MemoryInfo.h"
#import <mach/mach.h>

@implementation MemoryInfo

// 总内存大小 给int
+ (NSInteger)totalMemory {
    return [[NSProcessInfo processInfo] physicalMemory];
}
// 未使用内存大小 给int
+ (NSInteger)freeMemory {
    vm_statistics_data_t vmStats;
    mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
    kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
    if (kernReturn != KERN_SUCCESS) {
        return 0;
    }
    return (vm_page_size * vmStats.free_count + vm_page_size * vmStats.inactive_count);
}
@end
